package foliotracker.GUI;

import java.awt.Dimension;
import java.awt.GridLayout;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import foliotracker.Stock;
import foliotracker.views.IStockView;

public class StockView extends JPanel implements IStockView
{
	private static final long serialVersionUID = 1L;
	private Stock stock;
	private JTable table;
	
	public StockView(Stock stock)
	{
		super(new GridLayout(1, 0));
		
		this.stock = stock;
		
	    table = new JTable(new StockTableModel(stock));
	    table.setPreferredScrollableViewportSize(new Dimension(500, 70));
	    table.setAutoCreateRowSorter(true);
	    
	    //Create the scroll pane and add the table to it.
	    JScrollPane scrollPane = new JScrollPane(table);

	    //Add the scroll pane to this panel.
	    add(scrollPane);
	    scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
	
	}
	
	@Override
	public Stock getStock()
	{
		return stock;
	}
}
